package com.iapcursos.portal.procefet.modelo.beans.sessions;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.iapcursos.portal.procefet.modelo.beans.entitys.Disciplina;
import com.iapcursos.portal.procefet.modelo.beans.sessions.interfaces.GerenciadorDisciplinas;

@Stateless(mappedName="gerenciadorDisciplinas")
public class GerenciadorDisciplinasBean implements GerenciadorDisciplinas{

	@PersistenceContext(unitName="iap")
	private EntityManager entityManager;

	public GerenciadorDisciplinasBean() {

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Disciplina> recuperarDisciplinas() {
		Query consulta =  entityManager.createQuery("SELECT d FROM Disciplina d");
		List<Disciplina> disciplinas = consulta.getResultList();
		return disciplinas;
	}

	@Override
	public Disciplina recuperarDisciplina(int id) {
		Disciplina disciplina = new Disciplina();
		disciplina = entityManager.find(Disciplina.class, id);
		return disciplina;
	}
	
	
	
}
